package org.dizem.groupon.dao.impl;

import org.dizem.groupon.dao.ReplyDAO;
import org.dizem.groupon.model.domain.ReplyEntity;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
 * User: dizem
 * Time: 11-7-20 下午7:11
 */
public class ReplyDAOImpl extends DAOImplSupport<ReplyEntity> implements ReplyDAO {
	public ReplyEntity getById(int id) {
		return (ReplyEntity) getHibernateTemplate().get(ReplyEntity.class, id);
	}

	public List<ReplyEntity> loadAll() {
		return getHibernateTemplate().loadAll(ReplyEntity.class);
	}

	public List<ReplyEntity> load(int firstResult, int maxResult) {
		return getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(ReplyEntity.class), firstResult, maxResult);
	}

	public List<ReplyEntity> getByItemId(int id) {
		DetachedCriteria dc = DetachedCriteria.forClass(ReplyEntity.class);
		dc.add(Restrictions.eq("itemId", id));
		return getHibernateTemplate().findByCriteria(dc);
	}
}
